<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$item=$this->setting;
	$return['ischecklogin']=cfc('core')->checklogin('','',true);
	$jy_poster = $this->plugin_exists('jy_poster');
	$return['jy_poster']=$jy_poster?1:0;
	$mid=$_SESSION['uid'];
	pdo_update('jy_saleapp_list',array('readnum +'=>1),array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
	if($_RQ['fromuser']){
		$this->model('member')->uplog($_RQ['id'],$_RQ['fromuser']);
	}
	$app=pdo_get('jy_saleapp_list',array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
	$app['saleset']=json_decode($app['saleset'],true);
	$credit_types=credit_types();
	$yao_jitype=array('0'=>'阶梯式','1'=>'每人式');
	foreach($app['saleset'] as &$av){
		$av['yao_jitypetitle']=$yao_jitype[$av['yao_jitype']];
		$av['typetitle']=$credit_types[$av['type']];
	}
	$return['app']=$app;
	$return['member']=model('core/member')->detail($mid);
	$return['appregister']=custom_url('jy_saleapp/appregister//id='.$app['id'].'&snmid='.$return['member']['snmid'],true);
	$return['qrcode']=cfc('tools')->createqrcode($return['appregister'],'320',true);
	$return['qrcode']=tomedia($return['qrcode']);
	$return['item']=$item;
	$return['tips']='扫码下面二维码，前往下载安装'.$app['title'];
	$return['sharedata']=array(
				'title'=>$app['title']?$app['title'].'APP下载安装':'我的小店APP下载安装',
				'desc'=>$app['desc']?:'欢迎下载安装APP！',
				'link'=>custom_url('jy_saleapp/getapp//id='.$app['id'].'&snmid='.$return['member']['snmid'],true),
				'imgUrl'=>tomedia($item['logo']),
	);
	set_html('title','下载APP');
	exi($return);
}
if($_RQ['op']=='upposter'){
	$app=pdo_get('jy_saleapp_list',array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
	$mid=$_SESSION['uid'];
	$return['member']=model('core/member')->detail($mid);
	$url=custom_url('jy_saleapp/appregister//id='.$app['id'].'&snmid='.$return['member']['snmid'],true);
	$qr=cfc('tools')->createqrcode($url,'250',true);
	$qr=tomedia($qr);
	$image='oss/'.$_SESSION['uniacid'].'/images/jy_saleapp/mid'.$mid.'.jpg';
	$isadd=cfc('files')->source_check($image);
	if(!$isadd && $_SESSION['wxapp_id']){
		$wxappurl='/jy_saleapp/appregister/index?id='.$app['id'].'&snmid='.$return['member']['snmid'];
		$wxapp=pdo_get('core_account_wxapp',array('id'=>$_SESSION['wxapp_id'],'uniacid'=>$_SESSION['uniacid']));
		$res=model('core/wxapp')->appcode($wxappurl,$wxapp['appid'],$wxapp['appsecret'],200);
		$path='oss/'.$_SESSION['uniacid'].'/images/jy_saleapp/';
		if(!file_exists(ROOT_AT.$path)){
			mkdir(ROOT_AT.$path,0700, true);
		}
		$filename=$path.'/mid'.$mid.'.jpg';
		$qr=cfc('files')->source_save($res,'image','png','二维码',$filename,'',$wxappurl);
	}
	$posterset=$this->plugin_setting('poster');
	$posterset['data']['height']=930;
	foreach($posterset['data']['data'] as &$dv){
		if($dv['type']=='title'){
			$dv['type']='text';
			$dv['value']=$app['title'];
		}
		if($dv['type']=='desc'){
			$dv['type']='text';
			$dv['value']='我的邀请码：'.$return['member']['snmid'];
		}
	}
	$poster=plugin('jy_poster')->get_active('','',$orderid.'_'.$sn,$openid,$qr,$posterset['data'],'jy_saleapp');
	$poster['posterimg']=$poster['poster'];
	exi($poster);
}
?>